<?php
class IndexAction extends Action{
	public function _initialize(){//初始化
		R("Home.Public","top");
		R("Home.Public","bottom");
	}
	public function index(){
	   import("ORG.Com.DiyCache");
	   $mycache=new DiyCache;
	   if(!$mycache->is_cached()){//处理自定义缓存
	     //首页上部(958*90) 1 个
		 $typeid = 48;
		 $flash = M("flash");
		 $flash_index_top_one = $flash->where("typeid = $typeid")->order("sequence desc")->find();
		 $this->assign("flash_index_top_one",$flash_index_top_one);
		 
		 //产品分类及子类
	     $sysclass = M("sysclass");
		 $col_id = getcol_id("product");
		 $type_list = $sysclass->where("col_id = $col_id and parid = 0")->order("sequence desc")->findAll();
		 foreach($type_list as $k=>$v){
			 $typeid = $v['id'];
			 $type_list[$k]['child_type'] = $sysclass->where("parid = $typeid")->order("sequence desc")->field("id,class_name")->findAll();
		 }
		 $this->assign("type_list",$type_list);
		 
		 //首页四张切换(761*361) 
		 $typeid = 62;
		 $flash_index_four = $flash->where("typeid = $typeid")->order("sequence desc")->limit(4)->findAll();
		 $this->assign("flash_index_four",$flash_index_four);
		 
		 //首页中部四张(238*70)
		 $typeid = 63;
		 $flash_index_middle_four = $flash->where("typeid = $typeid")->order("sequence desc")->limit(4)->findAll();
		 $this->assign("flash_index_middle_four",$flash_index_middle_four);
		 
		 //读取  热卖  大图商品 一个
		 $product = M("product");
		 $hot_big_pr = $product->where("pr_rank ='热卖' and index_big_pr = '是'")->order("sequence desc")->find();
		 $this->assign("hot_big_pr",$hot_big_pr);
		 
		 //读取  热卖  类别
		 $typerank = M("typerank");
		 $hot_type_list = $typerank->where("index_rank like '%热卖%'")->order("sequence desc")->findAll();
		 //读取  热卖 类别 的商品
		 
		 $hot_pr = array();
		 
		 foreach($hot_type_list as $k => $v){
			 $typeid = $v['typeid'];
			 $hot_pr[$k]['id'] = $typeid;
			 $hot_pr[$k]['class_name'] = $sysclass->where("id = $typeid")->getField("class_name");
			 $map = array();
			 $map["typeid"] = array("in",typeid2child($typeid,"sysclass","col_id = {$col_id}"));
			 $map["pr_rank"] = "热卖";
			 
			 $map["index_big_pr"] = "否";
			 
			 $hot_pr[$k]['pr_list'] = $product->where($map)->order("sequence desc")->limit(6)->findAll();
		 }
		 
		 $this->assign("hot_pr",$hot_pr);
		 
		 
		 //读取  促销  大图商品 一个
		 $promot_big_map = array();
		 $promot_big_map["pr_rank"] = array("in",array("二折特价区","三折特价区","四折特价区"));
		 $promot_big_map["index_big_pr"] = "是";
		 
		 
		 $promot_big_pr = $product->where($promot_big_map)->order("sequence desc")->find();
		 $this->assign("promot_big_pr",$promot_big_pr);
		 
		 //读取  促销  类别
		 $promot_type_list = $typerank->where("index_rank like '%促销%'")->order("sequence desc")->findAll();
		 //读取  热卖 类别 的商品
		 
		 $promot_pr = array();
		 
		 foreach($promot_type_list as $k => $v){
			 $typeid = $v['typeid'];
			 $promot_pr[$k]['id'] = $typeid;
			 $promot_pr[$k]['class_name'] = $sysclass->where("id = $typeid")->getField("class_name");
			 $map = array();
			 $map["typeid"] = array("in",typeid2child($typeid,"sysclass","col_id = {$col_id}"));
			 $map["pr_rank"] = array("in",array("二折特价区","三折特价区","四折特价区","其他折价区"));
			 
			 $map["index_big_pr"] = "否";
			 
			 $promot_pr[$k]['pr_list'] = $product->where($map)->order("sequence desc")->limit(6)->findAll();
		 }
		 
		 $this->assign("promot_pr",$promot_pr);
		 
		 
		 //读取  推荐  大图商品 一个
		 $recommend_big_pr = $product->where("pr_rank ='推荐' and index_big_pr = '是'")->order("sequence desc")->find();
		 $this->assign("recommend_big_pr",$recommend_big_pr);
		 
		 //读取  推荐  类别
		 $typerank = M("typerank");
		 $recommend_type_list = $typerank->where("index_rank like '%推荐%'")->order("sequence desc")->findAll();
		 //读取  推荐 类别 的商品
		 
		 $recommend_pr = array();
		 
		 foreach($recommend_type_list as $k => $v){
			 $typeid = $v['typeid'];
			 $recommend_pr[$k]['id'] = $typeid;
			 $recommend_pr[$k]['class_name'] = $sysclass->where("id = $typeid")->getField("class_name");
			 $map = array();
			 $map["typeid"] = array("in",typeid2child($typeid,"sysclass","col_id = {$col_id}"));
			 $map["pr_rank"] = "推荐";
			 
			 $map["index_big_pr"] = "否";
			 
			 $recommend_pr[$k]['pr_list'] = $product->where($map)->order("sequence desc")->limit(6)->findAll();
		 }
		 
		 $this->assign("recommend_pr",$recommend_pr);
		 
		 
		 if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存
		 $this->display();
	   }
	   
	}
}
?>